import {request} from '@umijs/max';
import * as API from "@/services";
import {News_Query} from "@/services";
import {RespResult} from "kf-web-library";


/** 新闻 分页检索请求 */
export async function queryNewss(params: API.NewsPageQueryParams): Promise<API.RespPageResult<API.News>> {
  return request('/api/v1/news', {
    params,
  });
}

/** 新闻 详情请求 */
export async function queryNews(bizId: API.EntityId): Promise<API.RespResult<API.News>> {
  return request(`/api/v1/news/${bizId}`);
}

/** 新闻 创建请求 */
export async function createNews(entity: API.News_Create): Promise<API.RespResult<any>> {
  return request(`/api/v1/news`, {
    method: 'POST',
    data: entity,
  });
}

/** 新闻 修改请求 */
export async function modifyNews(entity: API.News_Modify): Promise<API.RespResult<any>> {
  return request(`/api/v1/news/${entity.id}`, {
    method: 'PUT',
    data: entity,
  });
}

/** 新闻 修改(部分)请求 */
export async function patchNews(entity: API.News_Patch): Promise<API.RespResult<any>> {
  return request(`/api/v1/news/${entity.id}`, {
    method: 'PATCH',
    data: entity,
  });
}

/** 上架 新闻请求 */
export async function upNews(bizId: API.EntityId): Promise<RespResult<any>> {
  return request(`/api/v1/news/${bizId}/open`, {
    method: 'PUT'
  });
}
/** 下架 新闻请求 */
export async function downNews(bizId: API.EntityId): Promise<RespResult<any>> {
  return request(`/api/v1/news/${bizId}/close`, {
    method: 'PUT'
  });
}

/** 新闻 删除请求 */
export async function deleteNews(bizId: API.EntityId): Promise<API.RespResult<any>> {
  return request(`/api/v1/news/${bizId}`, {
    method: 'DELETE',
  });
}

/** 新闻 批量删除请求 */
export async function deleteNewss(bizIds: API.EntityId[]): Promise<API.RespResult<any>> {
  return request(`/api/v1/news`, {
    method: 'DELETE',
    data: {
      ids: bizIds,
    },
  });
}


/** 新闻 获取所有分类和来源 */
export async function queryNewsParameter(): Promise<API.RespListResult<API.News_Query>> {
  return request('/api/v1/news/query-parameter', {
  });
}
